package ge.telasi.tasks.ui.comp;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import javax.swing.JButton;
import javax.swing.JPanel;

/**
 * @author dimitri
 */
public class CalendarDialog extends CommonDialog {
    private CalendarControl calControl;
    private boolean approved;

    public CalendarDialog(Component parent) {
        super(parent, true);
        initComponents();
        setTitle("აარჩიეთ თარიღი");
    }

    private void initComponents() {
        getContentPane().setLayout(new BorderLayout());
        calControl = new CalendarControl();
        getContentPane().add(calControl);
        JButton cancel = new JButton("გაუქმება");
        JButton ok = new JButton("არჩევა");
        JPanel pnl = new JPanel(new BorderLayout());
        pnl.add(ok, BorderLayout.EAST);
        pnl.add(cancel, BorderLayout.WEST);
        ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                approved = true;
                dispose();
            }
        });
        cancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                approved = false;
                dispose();
            }
        });
        getContentPane().add(pnl, BorderLayout.SOUTH);
        getRootPane().setDefaultButton(ok);
        pack();
    }

    public boolean isApproved() {
        return approved;
    }

    public Calendar getDate() {
        return calControl.getDate();
    }

    public void setDate(Calendar date) {
        calControl.setDate(date);
    }

}
